package com.ysm.smfu.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ListView;

/**
 * Created by Administrator on 2016/11/2.
 */
public class MySwipeListView extends ListView {

    private float x;
    private float downX;
    private float downY;

    public MySwipeListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MySwipeListView(Context context) {
        this(context, null);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {
        getParent().requestDisallowInterceptTouchEvent(true);
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                downX = event.getX();
                downY = event.getY();
                break;
            case MotionEvent.ACTION_MOVE:
                float moveX = event.getX();
                float moveY = event.getY();
                float disY = moveY - downY;
                float dixX = moveX - downX;
                if (Math.abs(disY) - Math.abs(dixX) > 100) {
                    return true;
                }
                downX = moveX;
                downY = moveY;
        }
        return super.onInterceptTouchEvent(event);
    }
}
